{% extends "default.html" %}
{% block title %}系统管理 - {{ app_id }}{% endblock %}

{% block pagecss %}
html{padding:0 !important;padding:32px 0 35px;}
.navi{width:100%;height:28px;border-bottom:1px solid #d6d6d6;box-shadow:0 0 3px #a6a6a6;position:fixed;top:0;left:0;right:0;background:#e3e3e3;background:linear-gradient(top,#fbfbfb,#e3e3e3);background:-o-linear-gradient(top,#fbfbfb,#e3e3e3);background:-ms-linear-gradient(top,#fbfbfb,#e3e3e3);background:-moz-linear-gradient(top,#fbfbfb,#e3e3e3);background:-webkit-linear-gradient(top,#fbfbfb,#e3e3e3);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fbfbfb',endColorstr='#e3e3e3',GradientType=0);}
.tool{width:100%;height:27px;line-height:30px;border-top:1px solid transparent;border-bottom:1px solid #d3d3d3;box-shadow:2px 1px 2px #a6a6a6;background:#e2e2e2;background:linear-gradient(top,#f8f8f8,#e2e2e2);background:-o-linear-gradient(top,#f8f8f8,#e2e2e2);background:-ms-linear-gradient(top,#f8f8f8,#e2e2e2);background:-moz-linear-gradient(top,#f8f8f8,#e2e2e2);background:-webkit-linear-gradient(top,#f8f8f8,#e2e2e2);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f8f8f8',endColorstr='#e2e2e2',GradientType=0);}
.cont{height:auto !important;height:100%;position:absolute;top:32px;bottom:0;left:0;right:0;width:100%;border:0;overflow:auto;}
.detl{float:left;width:100%;border:0;height:100%;}
.detl .listnav{height:100%;width:100%;float:left;margin:0;}
.itab{height:100%;}
.itab .on{height:100%;}
.chk input{margin:2px 1px;}
.t-c{text-align:center;}
.t-r{text-align:right;}
{% endblock %}

{% block content %}
<div id="sysmanage" class="detl">
<div id="syscont" class="listnav"></div>
</div>
{% endblock %}

{% block datas %}
<div id="prodmanage" class="detl">
    <div id="prodcont" class="listnav"></div>
</div>

<div id="stockmanage" class="detl"></div>
<div id="rptmanage" class="detl"></div>
<div id="salemanage" class="detl"></div>
<div id="vipmanage" class="detl"></div>
<div id="pomanage" class="detl"></div>
<div id="cstoremanage" class="detl"></div>
<div id="msgdata" style="width:200px;height:30px;" class="t-c"><div id="msgdatatext">发送数据中....</div><div class="iloading"><div class="ianim"></div></div></div>
<div id="vipsel" class="detl" style="height:585px;"></div>
<div id="prodsel" class="detl" style="height:586px;"></div>
<div id="poedit" class="detl" style="height:620px;"><table class="idatable"><tbody class="dtbody"><tr class="ditem"><td class="col px50">店名：</td><td class="col px160" id="pocsname"></td><td class="col px60">订单号：</td><td class="col px120" id="pono"></td><td class="col px60">总金额：</td><td class="col px70 t-r" id="poamount"></td><td class="colnone"></td></tr></tbody></table></div>
{% endblock %}

{% block jscript %}
var data = {
    pvtype:{
        {% if pvtypes %}{% for pvt in pvtypes %}'{{ pvt.key }}':{'guid':'{{ pvt.key }}', 'ptcode':'{{ pvt.code }}', 'ptname':'{{ pvt.name }}', 'ratepv':'{{ pvt.ratepv }}', 'pvrate':'{{ pvt.pvrate }}', 'bvrate':'{{ pvt.bvrate }}', 'locked':'{% if pvt.locked %}yes{% else %}no{% endif %}', 'lockin':'{% if pvt.locked %}&#10008;{% else %}&#10004;{% endif %}'}{% if not forloop.last %},{% endif %}{% endfor %}{% endif %}
        },
    prodpic:{
        {% if prods %}{% for prod in prods %}'{{ prod.key }}':{'guid':'{{ prod.key }}','pcode':'{{ prod.code }}', 'pname':'{{ prod.name }}', 'spec':'{{ prod.spec }}', 'pclass':'{{ prod.refcls.key }}', 'pclassname':'{{ prod.refcls.name }}', 'pvtype':'{{ prod.pvtype.key }}', 'pvtypename':'{{ prod.pvtype.name }}', 'unit':'{{ prod.unit }}', 'price':{{ prod.price }}, 'ppic':'<a href="/pp/{{ prod.picid }}" target="_blank">查看</a>'}{% if not forloop.last %},{% endif %}{% endfor %}{% endif %}
        },
    prodclass:{
        {% if pclass %}{% for pcls in pclass %}'{{ pcls.key }}':{'guid':'{{ pcls.key }}', 'clscode':'{{ pcls.code }}', 'clsname':'{{ pcls.name }}', 'refcls':'{{ pcls.refcls.key }}', 'refclscode':'{% if pcls.refcls %}{{ pcls.refcls.code }}{% else %}无{% endif %}', 'clscss':'{{ pcls.csstyle }}'}{% if not forloop.last %},{% endif %}{% endfor %}{% endif %}
        },
    stocks:{  },
    optcsnoab:{ {% if optcmpnyab %}{% for cacb in optcmpnyab %}'{{ cacb.key }}':{'guid':'{{ cacb.key }}', 'acode':'{{ cacb.code }}', 'aname':'{{ cacb.name }}'}{% if not forloop.last %},{% endif %}{% endfor %}{% endif %} },
    optbcmpny:{ {% if optcmpny %}{% for cb in optcmpny %}'{{ cb.key }}':{'guid':'{{ cb.key }}', 'acode':'{{ cb.code }}', 'aname':'{{ cb.name }}'}{% if not forloop.last %},{% endif %}{% endfor %}{% endif %} },
    optastore:{ {% if optstore %}{% for aa in optstore %}'{{ aa.key }}':{'guid':'{{ aa.key }}', 'acode':'{{ aa.code }}', 'aname':'{{ aa.name }}'}{% if not forloop.last %},{% endif %}{% endfor %}{% endif %} },
    optguid:{},
    optvips:{},
    optprods:{},
    roles:{
        {% if roles %}{% for role in roles %}'{{ role.key }}':{'guid':'{{ role.key }}', 'rolename':'{{ role.name }}', 'tpurl':'{{ role.tpurl }}'}{% if not forloop.last %},{% endif %}{% endfor %}{% endif %}
        }
    };
var fres = {
    fform:[{'type':'text', name:'formid', label:'表单ID：', tips:'不能重复', fontcase:'lower'},
        {'type':'text', name:'formaction', label:'表单 action', tips:'格式如：“/action”', fontcase:'lower'},
        {'type':'radio', 'name':'formethod', 'label':'post', value:'post', checked:1, text:'表单 method'},
        {'type':'radio', 'name':'formethod', 'label':'get', value:'get'},
        {'type':'text', name:'formstyle', label:'style class：'},
        {'type':'radio', 'name':'formfile', 'label':'包含文件项', value:'yes', text:'表单包含文件项：'},
        {'type':'radio', 'name':'formfile', 'label':'不含文件项', value:'no', checked:1},
        {'type':'text', name:'formtitle', label:'表单标题：'}
        ],
    roles:[{'type':'text', name:'rolename', label:'名称：', autofocus:1, fontcase:'upper', valid:'type:str;adv:请输入名称'},
        {'type':'text', name:'tpurl', label:'URL：', fontcase:'lower', valid:'type:str;adv:请输入URL'}
        ],
    admins:[{'type':'text', name:'email', label:'账号（邮箱）：', autofocus:1, fontcase:'lower', valid:'type:email;adv:请输入email'},
        {'type':'text', name:'name', label:'姓名：', valid:'type:str;adv:请输入姓名'},
        {'type':'select', 'name':'role', 'label':'帐号类别：', 'text':'请选择 ....', value:'', opts: function(){return getopts(data.roles,'guid','rolename');}, valid:'type:str;adv:请选择类别'},
        {'type':'select', 'name':'refcstore', 'label':'所属公司/店：', 'text':'请选择 ....', value:'', opts: function(){return getopts(data.cstore,'guid','aname');}, valid:'type:str;adv:请选择公司/专卖店'},
        {'type':'radio', name:'isadmin', label:'是', text:'管理员：', value:'yes'},
        {'type':'radio', name:'isadmin', label:'否', value:'no', checked:1}
        ],
    prods:[{'type':'text', name:'pcode', label:'产品编号：', tips:'产品的erp编码', autofocus:1, fontcase:'upper', valid:'type:code;adv:请输入编号'},
        {'type':'text', name:'pname', label:'产品名称：', valid:'type:str;adv:请输入名称'},
        {'type':'text', name:'spec', label:'产品规格：', tips:'如：10g × 10袋 / 盒', valid:'type:str;adv:请输入规格'},
        {'type':'select', 'name':'unit', 'label':'基本单位：', 'text':'请选择 ....', value:'', valid:'type:str;adv:请选择单位',
            opts:[{'text':'瓶', value:'瓶'},{'text':'盒', value:'盒'},
            {'text':'台', value:'台'},{'text':'罐', value:'罐'},{'text':'支', value:'支'},{'text':'块', value:'块'},
            {'text':'本', value:'本'},{'text':'张', value:'张'},{'text':'个', value:'个'},{'text':'条', value:'条'},
            {'text':'把', value:'把'},{'text':'包', value:'包'},{'text':'套', value:'套'}]},
        {'type':'select', 'name':'pvtype', 'label':'PVBV类型：', 'text':'请选择 ....', value:'', opts: function(){return getopts(data.pvtype,'guid','ptname');}, valid:'type:str;adv:请选择PVBV类型'},
        {'type':'select', 'name':'pclass', 'label':'产品类别：', 'text':'请选择 ....', value:'', opts: function(){return getopts(data.prodclass,'guid','clsname');}, valid:'type:str;adv:请选择类别'},
        {'type':'text', name:'price', label:'价格：', valid:'type:price;adv:请输入正确价格'},
        {'type':'radio', name:'status', label:'正 常', text:'状态：', value:'active',checked:1},
        {'type':'radio', name:'status', label:'断 货', value:'soldout'},
        {'type':'radio', name:'status', label:'不可用', value:'locked'},
        {'type':'radio', name:'status', label:'退市', value:'exitmarket'},
        {'type':'radio', name:'sepreport', label:'是', text:'需单独报单：', value:'yes'},
        {'type':'radio', name:'sepreport', label:'否', value:'no', checked:1},
        {'type':'file', name:'fpic', label:'产品图样：', accept:'image/*', tips:'只支持 jpg, png, 不大于500KB'}
        ],
    pvtype:[{'type':'text', name:'ptcode', label:'PVBV类型编号：',tips:'如：PV100BV100', fontcase:'upper', valid:'type:code;adv:请输入编号'},
        {'type':'text', name:'ptname', label:'PVBV类型名称：', valid:'type:str;adv:请输入名称'},
        {'type':'text', name:'ratepv', label:'净额比例(%)：', value:85, tips:'0~100的整数，其他字符将为0'},
        {'type':'text', name:'pvrate', label:'PV比例(%)：', tips:'0~100的整数，其他字符将为0'},
        {'type':'text', name:'bvrate', label:'BV比例(%)：', tips:'0~100的整数，其他字符将为0'},
        {'type':'radio', name:'locked', label:'可用', text:'锁定：', value:'no',checked:1},
        {'type':'radio', name:'locked', label:'不可用', value:'yes'}
        ],
    prodclass: [{'type':'select', 'name':'refcls', 'label':'上级类型：', 'text':'请选择 ....', value:'', opts: function(){return getopts(data.prodclass,'guid','clsname');}},
        {'type':'text', name:'clscode', label:'基本类型编号：', tips:'自定义编号，不要重复', fontcase:'upper', valid:'type:code;adv:请输入编号'},
        {'type':'text', name:'clsname', label:'基本类型名称：', valid:'type:str;adv:请输入名称'},
        {'type':'text', name:'clscss', label:'显示样式：', fontcase:'lower', tips:'css代码'}
        ],
    cstore:[{'type':'select', 'name':'atype', 'label':'授权经销店类型：', 'text':'请选择 ....', value:'', opts:[{'text':'总公司', value:'ca'},{'text':'分公司', value:'cb'},{'text':'A店', value:'aa'},{'text':'B店', value:'ab'}], valid:'type:str;adv:请选择类型'},
        {'type':'select', 'name':'regref', 'label':'所属单位：', text:'请选择...', value:'', opts: function(){return getopts(data.optcsnoab,'guid','aname');}},
        {'type':'text', 'name':'acode', 'label':'授权经销店编号：', tips:'如：CN000001', fontcase:'upper', valid:'type:code;adv:请输入编号'},
        {'type':'text', 'name':'aname', 'label':'授权经销店名称：', valid:'type:str;adv:请输入名称'},
        {'type':'select', 'name':'owner', 'label':'负责人：', text:'请选择...', value:'', opts: function(){return getopts(data.admins,'guid','name');}},
        {'type':'text', 'name':'addr', 'label':'地址：', valid:'type:str;adv:地址不能为空'},
        {'type':'text', 'name':'postcode', 'label':'邮政编码：'},
        {'type':'text', 'name':'phone', 'label':'固定电话：'},
        {'type':'text', 'name':'mobile', 'label':'手机号码：'},
        {'type':'select', 'name':'refpo', 'label':'进货单位：', tips:'默认从此单位进货', text:'请选择...', value:'', opts: function(){return getopts(data.optcsnoab,'guid','aname');}}
        ],
    vips:[{'type':'select', 'name':'refcomp', 'label':'公司/分公司：', text:'请选择...', value:'', opts: function(){return getopts(data.optbcmpny,'guid','aname');}},
        {'type':'select', 'name':'refstore', 'label':'授权经销店：', text:'请选择...', value:'', opts: function(){return getopts(data.optastore,'guid','aname');}},
        {'type':'icalendar', 'name':'jdate', 'label':'加入日期：', tips:'如当月报单已结束，请选下一月份', readonly:1},/* 选择正确的年份月份，日期选任一天均可。日期将自动设为该月份20日。 */
        {'type':'iselect', 'name':'refvip', 'textname':'refvipid', 'label':'老顾客：', topopt:[{text:'请选择...', value:''}], readonly:1, optwidth:206, seltype:'pop', pop:'vipsel', opts:function(){return getopts(data.optvips, 'guid', 'refvipid', 'vipname');}, fontcase:'upper'},
        {'type':'text', 'name':'idcard', 'label':'顾客的身份证号码：', autofocus:1, tips:'顾客自己的15或18位身份证号码', fontcase:'upper', valid:'type:idcard;adv:请输入正确的身份证号码;'},
        {'type':'text', 'name':'uname', 'label':'姓名：', placeholder:'顾客姓名', valid:'type:str;adv:请输入姓名'},
        {'type':'radio', 'name':'gender', 'label':'男', value:'yes', text:'性别：'},
        {'type':'radio', 'name':'gender', 'label':'女', value:'no', checked:1},
        {'type':'text', 'name':'vcard', 'label':'卓越卡号码：'},
        {'type':'text', 'name':'vcardsn', 'label':'卓越卡背面SN：', placeholder:'如：8888-8888-8888'},
        {'type':'text', 'name':'phone', 'label':'电话号码：'},
        {'type':'text', 'name':'mobile', 'label':'手机号码：'}
        ],
    stocks:[
        {'type':'iselect', 'name':'prod', 'textname':'pcode', textvalue:'title', 'label':'产品：', tips:'产品编码', valid:'type:str;adv:产品不能为空', readonly:1, optwidth:330,titlewidth:80, seltype:'pop', pop:'prodsel', opts:function(){return getopts(data.optprods, 'guid', 'pname', 'pcode');}, fontcase:'upper', onchange: function(){if(this.value){setForm(data.optguid[this.value], this.form, {name:['guid']});}}},
        {'type':'text', name:'pname', label:'产品名称：', readonly:1},
        {'type':'text', name:'unit', label:'单位：', readonly:1},
        {'type':'text', 'name':'qty', 'label':'数量：', valid:'type:nz;adv:请输入大于0的整数'}
        ],
    sales:[
        {'type':'text', 'name':'refbill', 'label':'购货单：', valid:'type:str;adv:不能为空'},
        {'type':'icalendar', 'name':'date', 'label':'日期：', tips:'购货日期', readonly:1, valid:'type:str;adv:日期不能为空'},
        {'type':'iselect', 'name':'vip', 'textname':'vipid', 'label':'顾客/业务员：', tips:'顾客/业务员号码', readonly:1, valid:'type:str;adv:顾客/业务员不能为空', optwidth:206, seltype:'pop', pop:'vipsel', opts:function(){return getopts(data.optvips, 'guid', 'vipid', 'vipname');}, fontcase:'upper'},
        {'type':'iselect', 'name':'prod', 'textname':'pcode', textvalue:'title', 'label':'产品：', tips:'产品编码', readonly:1, valid:'type:str;adv:产品不能为空', optwidth:330,titlewidth:80, seltype:'pop', pop:'prodsel', opts:function(){return getopts(data.optprods, 'guid', 'pname', 'pcode');}, fontcase:'upper', onchange: function(){if(this.value){setForm(data.optguid[this.value],this.form, {name:['guid']});}}},
        {'type':'text', 'name':'price', 'label':'单价：', value:'请选择产品，单价会自动显示', readonly:1},
        {'type':'hidden', 'name':'sepreport', 'value':'no'},
        {'type':'text', 'name':'qty', 'label':'数量：', valid:'type:nz;adv:请输入大于0的整数'}
        ],
    fbtn:[{name:'action', type:'hidden', value:'addnew'}, {name:'guid', type:'hidden', value:''}, { name:'submit', type: 'submit', text:'确定', ico:'{{ imgsurl }}/icos/tick.png' }, { name:'reset', type: 'reset', text:'重置', ico:'{{ imgsurl }}/icos/arrow_undo.png' }],
    faddnew:{'action':'addnew','guid':''},fmodify:{'action':'modify'},fdelete:{'action':'delete'}
    };
def('msgpop', 'ipop', {id: 'msgpopup', notitle:1, z:30000 });
function msgalert(t){$('msgdatatext').html(t);msgpop.show({data:$('msgdata')});}
function oasubmit(odt, css){
    if(!odt || odt.uitype!='idatable'){
        return false;
    }
    //msgalert('提交数据中....');
    var fo = oaform.form,
        sender = aja$({url: attr(fo, 'action'), data: jsonForm(fo)}, {uprogress: function(e){
        var ttl=e.total, lod=e.loaded;
        if(e.lengthComputable){
            msgalert('提交数据中....'+ (lod/ttl*1000).int10()/10 +'%');
        }},
        uploadend: function(e){
        },
        finish: function(a){
            if ( /^error/i.test(a) ) {
                alert(a.split('!?')[1]);
            } else if ( /^success/i.test(a) ) {
                var od = !css ? a.split('!?')[1].jsonQs() : a.split('!?')[1].jsonCss();
                if (hop( od, 'guid' )) {
                    var oa = {};
                    oa[od.guid] = od;
                    odt.setBody(oa).pager();
                }
            } else {
                alert(a);
            }
            msgpop.hide();
            fo.reset();
        }
    });
}
function prodadd(odt){
    if(!odt || odt.uitype!='idatable'){
        return false;
    }
    var fo = oaform.form,
        sender = aja$({url: attr(fo, 'action'), filedata: formData(fo)}, {finish: function(a){
            if ( /^error/i.test(a) ) {
                alert(a.split('!?')[1]);
            } else if ( /^success/i.test(a) ) {
                var od = JSON.parse( a.split('!?')[1] );
                odt.setBody(od).pager();
            } else {
                alert(a);
            }
            fo.reset();
        }
    });
}
var foms = {
    pvtype:{action:'/tiens/pvtype', data:fres.pvtype.concat(fres.fbtn), onsubmit:function(){oasubmit(dtpvt,1); return false;} },
    vips: { action:'/tiens/vip', data:fres.vips.concat(fres.fbtn), onsubmit:function(){oasubmit(dtvip); return false;} },
    prods: {action:'/tiens/prods', data:fres.prods.concat(fres.fbtn), onsubmit:function(){ return true;prodadd(dtprod);return false;} },
    cstore: {action:'/tiens/cstore', data:fres.cstore.concat(fres.fbtn), onsubmit:function(){oasubmit(dtcs); return false; } },
    prodclass:{action:'/tiens/prodclass', data:fres.prodclass.concat(fres.fbtn), onsubmit:function(){oasubmit(dtpcls); return false; } },
    roles:{action:'/tiens/roles', data:fres.roles.concat(fres.fbtn), onsubmit:function(){oasubmit(dtrole); return false; } },
    admins:{action:'/tiens/admins', data:fres.admins.concat(fres.fbtn), onsubmit:function(){oasubmit(dtadmin,1); return false; } },
    stocks: { action:'/tiens/stock', data:fres.stocks.concat(fres.fbtn), onsubmit:function(){oasubmit(dtstock); return false; } },
    sales: { action:'/tiens/sales', data:fres.sales.concat(fres.fbtn), onsubmit:function(){oasubmit(dtsale,1); return false; } }
    };
function amod (opt) {
    var opt = ext({add:'', title:'', mod:''}, opt);
    if (hop(foms, opt.add)) {
        var tit = '新增：',
            ico = '{{ imgsurl }}/icos/add.png';
        oaform.reset(ext(foms[opt.add], opt.fn));
        if(opt.mod && typeof opt.mod=='object'){
            tit = '修改：';
            ico = '{{ imgsurl }}/icos/page_edit.png';
            setForm(opt.mod, oaform.form);
            setForm(fres.fmodify, oaform.form);
        } else {
            setForm(fres.faddnew, oaform.form);
        }
        oapop.show({'data':oaform.form, 'ico':ico, 'title':tit+opt.title});
    }
}
function getopts(data, value, text, title){
    var opts=[];
    for ( var k in data){
        if (title){
            opts.push({'value':data[k][value], 'text':{'title':data[k][title], 'text':data[k][text]}});
        } else {
            opts.push({'value':data[k][value], 'text':data[k][text]});
        }
    }
return opts;
}
function deldtdata( odt ){
    if(!odt || odt.uitype!='idatable'){
        return false;
    }
    var fo = odt.form,
        ofo = jsonForm(fo);
    if(hop(ofo, 'guid')){
        var sender = aja$({url:fo.action, data: ext(ofo, fres.fdelete)}, { finish: function(a){
            if ( /^error/i.test(a) ) {
                alert(a.split('!?')[1]);
            } else if ( /^success/i.test(a) ) {
                var od = a.split('!?')[1].jsonQs();
                odt.setBody(od,1).pager();
            } else {
                alert(a);
            }
        } });
    }
}

def('oapop', 'ipop', {id: 'oapopup' });

def( 'fform', 'iform', { id: 'resform', elem:'datapool', action:'/tiens/resform', data:fres.fform.concat(fres.fbtn)});

def( 'oaform', 'iform', { id: 'oaforms', elem:'datapool', onreset:function () {
        if (this.action.value=='addnew'){
            try {
                this.elements[0].focus();
            } catch (e) {}
            return true;
        }
        oapop.hide();
    } } );

def( 'dtcs', 'idatable', {id:'csdata', elem:'cstoremanage', tool:{cls:'tool', menu:[{id: 'csadd', ico: {src: '{{ imgsurl }}/icos/add.png'}, label: {txt: '新增'}, fn:"amod({add:'cstore', title:'公司/专卖店'});" }, { label: {txt: '-|-'} }, {id: 'csedit', ico: {src: '{{ imgsurl }}/icos/page_edit.png'}, label: {txt: '修改'},fn:function(){var ofo=jsonForm(dtcs.form);if(hop(ofo,'guid')){amod({add:'cstore', title:'公司/专卖店',mod:data.cstore[isArray(ofo.guid)?ofo.guid[0]:ofo.guid]});}}}, { label: {txt: '-|-'} }, {id: 'csdel', ico: {src: '{{ imgsurl }}/icos/delete.png'}, label: {txt: '删除'},fn:function(){ deldtdata(dtcs); }} ]},
    filter:{action:'/tiens/cstore'},
    title:[{cls:'px100',text:'编码',col:'acode'},{cls:'px160',text:'名称',col:'aname'},{cls:'px40',text:'类型',col:'atype'},{cls:'px100',text:'所属编码',col:'refcode'}], data:data.cstore});
def( 'dtvip', 'idatable', {id:'vipdata', elem:'vipmanage', tool:{cls:'tool', menu:[{id: 'vipadd', ico: {src: '{{ imgsurl }}/icos/add.png'}, label: {txt: '新增'}, fn:"amod({add:'vips', title:'顾客/业务员'});" }, { label: {txt: '-|-'} }, {id: 'vipedit', ico: {src: '{{ imgsurl }}/icos/page_edit.png'}, label: {txt: '修改'},fn:function(){var ofo=jsonForm(dtvip.form);if(hop(ofo,'guid')){amod({add:'vips', title:'顾客/业务员',mod:data.vips[isArray(ofo.guid)?ofo.guid[0]:ofo.guid]});}}}, { label: {txt: '-|-'} }, {id: 'vipdel', ico: {src: '{{ imgsurl }}/icos/delete.png'}, label: {txt: '删除'},fn:function(){ deldtdata(dtvip); }} ]},
    filter:{action:'/tiens/vip', col:{ vip_name:'', vipid:'', jmonth: {type:'select', value:'', text:'不分先后', opts:function(){var ym=[{value:'later', text:'日期▼排序'},{value:'earlier', text:'日期▲排序'}],y9=now().getFullYear(),m9=now().getMonth()+1;for(var y=y9;y>2009;y--){for(var m=12;m>0;m--){ if(y==y9 && m>m9){continue;}else{var v=y+'-'+(m>9?m:'0'+m);ym.push({value:v, text:v});} }}return ym.concat([{value:'2009-12', text:'2009-12'},{value:'2009-11', text:'2009-11'},{value:'outearlier', text:'09-11之前'}]);}}}},
    title:[{cls:'px70',text:'姓名',col:'vip_name'},{cls:'px140',text:'身份证号码',col:'vipid'}, {cls:'px60',text:'加入时间',col:'jmonth'}, {cls:'px70',text:'老顾客',col:'refvipname'}, {cls:'px140',text:'老顾客身份证',col:'refvipid'}], data:data.vips});
def( 'dtprod', 'idatable', {id:'prodata', elem:'datapool', tool:{cls:'tool', menu:[{id: 'prodadd', ico: {src: '{{ imgsurl }}/icos/add.png'}, label: {txt: '新增'}, fn:"amod({add:'prods', title:'产品'});" }, { label: {txt: '-|-'} }, {id: 'prodedit', ico: {src: '{{ imgsurl }}/icos/page_edit.png'}, label: {txt: '修改'},fn:function(){var ofo=jsonForm(dtprod.form);if(hop(ofo,'guid')){amod({add:'prods', title:'产品', mod:data.prods[isArray(ofo.guid)?ofo.guid[0]:ofo.guid]});}}}, { label: {txt: '-|-'} }, {id: 'proddel', ico: {src: '{{ imgsurl }}/icos/delete.png'}, label: {txt: '删除'},fn:function(){ deldtdata(dtprod); } } ]},
    filter:{action:'/tiens/prods', col:{'pcode':'', pvtypename:{type:'select', value:'all', text:'所有PVBV类型', opts:function(){return getopts(data.pvtype,'guid','ptname');}} } },
    title:[{cls:'px80',text:'编码',col:'pcode'},{cls:'px220',text:'名称',col:'pname'},{cls:'px120',text:'规格',col:'spec'}, {cls:'px160',text:'产品类别',col:'pclassname'}, {cls:'px200',text:'PVBV类型',col:'pvtypename'}, {cls:'px40 t-c',text:'单位',col:'unit'}, {cls:'px50 t-r',text:'价格',col:'price'}, {cls:'px40 t-c',text:'图样',col:'ppic'}, {cls:'px40 t-c',text:'状态',col:'statuslbl'}], data:data.prods});
def( 'dtpvt', 'idatable', {id:'prodpvtype', elem:'datapool', tool:{cls:'tool', menu:[{id: 'pvtadd', ico: {src: '{{ imgsurl }}/icos/add.png'}, label: {txt: '新增'}, fn:"amod({add:'pvtype', title:'产品PVBV类型'});" }, { label: {txt: '-|-'} }, {id: 'pvtedit', ico: {src: '{{ imgsurl }}/icos/page_edit.png'}, label: {txt: '修改'},fn:function(){var ofo=jsonForm(dtpvt.form);if(hop(ofo,'guid')){amod({add:'pvtype', title:'产品PVBV类型', mod:data.pvtype[isArray(ofo.guid)?ofo.guid[0]:ofo.guid]});}}}, { label: {txt: '-|-'} }, {id: 'pvtdel', ico: {src: '{{ imgsurl }}/icos/delete.png'}, label: {txt: '删除'},fn:function(){ deldtdata(dtpvt); }} ]},
    filter:{action:'/tiens/pvtype'},
    title:[{cls:'px120',text:'编码',col:'ptcode'},{cls:'px200',text:'名称',col:'ptname'},{cls:'px50 t-r',text:'净额(%)',col:'ratepv'}, {cls:'px50 t-r',text:'PV(%)',col:'pvrate'}, {cls:'px50 t-r',text:'BV(%)',col:'bvrate'}, {cls:'px40 t-c',text:'可用',col:'lockin'}], data:data.pvtype});
def( 'dtpcls', 'idatable', {id:'prodclsdata', elem:'datapool', tool:{cls:'tool', menu:[{id: 'pclsadd', ico: {src: '{{ imgsurl }}/icos/add.png'}, label: {txt: '新增'}, fn:"amod({add:'prodclass', title:'产品类别'});" }, { label: {txt: '-|-'} }, {id: 'pclsedit', ico: {src: '{{ imgsurl }}/icos/page_edit.png'}, label: {txt: '修改'},fn:function(){var ofo=jsonForm(dtpcls.form);if(hop(ofo,'guid')){amod({add:'prodclass', title:'产品类别', mod:data.prodclass[isArray(ofo.guid)?ofo.guid[0]:ofo.guid]});}}}, { label: {txt: '-|-'} }, {id: 'pclsdel', ico: {src: '{{ imgsurl }}/icos/delete.png'}, label: {txt: '删除'},fn:function(){ deldtdata(dtpcls); }} ]},
    filter:{action:'/tiens/prodclass'},
    title:[{cls:'px80',text:'编码',col:'clscode'},{cls:'px160',text:'名称',col:'clsname'},{cls:'px80',text:'所属编码',col:'refclscode'}, {cls:'px200',text:'css样式',col:'clscss'}], data:data.prodclass});
def( 'dtadmin', 'idatable', {id:'admindata', elem:'datapool', tool:{cls:'tool', menu:[{id: 'admadd', ico: {src: '{{ imgsurl }}/icos/add.png'}, label: {txt: '新增'}, fn:"amod({add:'admins', title:'帐号'});" }, { label: {txt: '-|-'} }, {id: 'admedit', ico: {src: '{{ imgsurl }}/icos/page_edit.png'}, label: {txt: '修改'},fn:function(){var ofo=jsonForm(dtadmin.form);if(hop(ofo,'guid')){amod({add:'admins', title:'帐号', mod:data.admins[isArray(ofo.guid)?ofo.guid[0]:ofo.guid]});}}}, { label: {txt: '-|-'} }, {id: 'admdel', ico: {src: '{{ imgsurl }}/icos/delete.png'}, label: {txt: '删除'},fn:function(){ deldtdata(dtadmin); }} ]},
    filter:{action:'/tiens/admins'},
    title:[{cls:'px200',text:'账号（邮箱）',col:'email'},{cls:'px100',text:'姓名',col:'name'},{cls:'px160',text:'所属店',col:'refcsname'}, {cls:'px140',text:'Role name',col:'rolename'}, {cls:'px40 t-c',text:'admin',col:'admin'}], data:data.admins});
def( 'dtrole', 'idatable', {id:'roledata', elem:'datapool', tool:{cls:'tool', menu:[{id: 'roleadd', ico: {src: '{{ imgsurl }}/icos/add.png'}, label: {txt: '新增'}, fn:"amod({add:'roles', title:'帐号角色'});" }, { label: {txt: '-|-'} }, {id: 'roleedit', ico: {src: '{{ imgsurl }}/icos/page_edit.png'}, label: {txt: '修改'},fn:function(){var ofo=jsonForm(dtrole.form);if(hop(ofo,'guid')){amod({add:'roles', title:'帐号角色', mod:data.roles[isArray(ofo.guid)?ofo.guid[0]:ofo.guid]});}}}, { label: {txt: '-|-'} }, {id: 'roledel', ico: {src: '{{ imgsurl }}/icos/delete.png'}, label: {txt: '删除'},fn:function(){ deldtdata(dtrole); }} ]},
    filter:{action:'/tiens/roles'},
    title:[{cls:'px140',text:'角色名称',col:'rolename'},{cls:'px200',text:'url',col:'tpurl'}], data:data.roles});
def( 'dtrpt', 'idatable', {id:'rptdata', elem:'rptmanage', paging:{pagesize:15},
    filter:{action:'/tiens/pvreport'},
    title:[{cls:'px70',text:'顾客/业务员',col:'vipname'}, {cls:'px140',text:'身份证号码',col:'vipid'}, {cls:'px160',text:'PVBV类型',col:'pvtypename'}, {cls:'px70 t-r',text:'业绩金额',col:'amount'}, {cls:'px70 t-r',text:'净额PV',col:'pv'}, {cls:'px70 t-r',text:'净额BV',col:'bv'}], data:data.report});
def( 'dtsale', 'idatable', {id:'saledata', elem:'salemanage', paging:{pagesize:15}, tool:{cls:'tool', menu:[{id: 'saleadd', ico: {src: '{{ imgsurl }}/icos/add.png'}, label: {txt: '新增'}, fn:"amod({add:'sales', title:'销售项'});" }, { label: {txt: '-|-'} }, {id: 'saleedit', ico: {src: '{{ imgsurl }}/icos/page_edit.png'}, label: {txt: '修改'},fn:function(){var ofo=jsonForm(dtsale.form);if(hop(ofo,'guid')){amod({add:'sales',title:'销售项',mod:data.sales[isArray(ofo.guid)?ofo.guid[0]:ofo.guid]});}}}, { label: {txt: '-|-'} }, {id: 'saledel', ico: {src: '{{ imgsurl }}/icos/delete.png'}, label: {txt: '删除'},fn:function(){ deldtdata(dtsale); }} ]},
    filter:{action:'/tiens/sales'},
    title:[{cls:'px70',text:'日期',col:'date'}, {cls:'px70',text:'顾客/业务员',col:'vipname'}, {cls:'px140',text:'编号',col:'vipid'}, {cls:'px80',text:'产品编码',col:'pcode'}, {cls:'px220',text:'产品名称',col:'pname'}, {cls:'px160',text:'PVBV类型',col:'prodpvt'}, {cls:'px40 t-c',text:'单位',col:'unit'}, {cls:'px50 t-r',text:'单价',col:'price'}, {cls:'px60 t-r',text:'数量',col:'qty'}, {cls:'px70 t-r',text:'购货金额',col:'amount'}/* , {cls:'px70 t-r',text:'净额PV',col:'pv'}, {cls:'px70 t-r',text:'净额BV',col:'bv'} */], data:data.sales});
def( 'dtvipsel', 'idatable', {id:'vipseldata', elem:'vipsel', tool:{cls:'tool', menu:[{id: 'pickvip', ico: {src: '{{ imgsurl }}/icos/tick.png'}, label: {txt: '选择'}, fn:function(){var ofo = jsonForm(dtvipsel.form);if(hop(ofo, 'guid')){
    setForm(data.optvips[isArray(ofo.guid)?ofo.guid[0]:ofo.guid], oaform.form, {name:['guid']}); try{iselect_pop.hide();}catch(e){} }}} ]},
    filter:{action:'/tiens/vip?opt=yes', col:{ vip_name:'', vipid:'' }},
    title:[{cls:'px70',text:'姓名',col:'vip_name'},{cls:'px140',text:'身份证号码',col:'vipid'}], fn:function(){ext(data.optguid, osort$(data.optvips, 'guid'));}, data:data.optvips});
def( 'dtprodsel', 'idatable', {id:'prodseldata', elem:'prodsel', tool:{cls:'tool', menu:[{id: 'pickprod', ico: {src: '{{ imgsurl }}/icos/tick.png'}, label: {txt: '选择'}, fn:function(){var ofo = jsonForm(dtprodsel.form);if(hop(ofo, 'guid')){
    setForm(data.optprods[isArray(ofo.guid)?ofo.guid[0]:ofo.guid], oaform.form, {name:['guid']}); try{iselect_pop.hide();}catch(e){} }}} ]},
    filter:{action:'/tiens/prods?opt=yes', col:{pcode:'',pvtypename:{type:'select', value:'all', text:'所有PVBV类型', opts:function(){return getopts(data.pvtype,'guid','ptname');}}}},
    title:[{cls:'px80',text:'编码',col:'pcode'},{cls:'px220',text:'名称',col:'pname'}, {cls:'px30 t-c',text:'单位',col:'unit'}, {cls:'px50 t-r',text:'单价',col:'price'}, {cls:'px200',text:'PVBV类型',col:'pvtypename'}], fn:function(){ext(data.optguid, osort$(data.optprods, 'guid'));}, data:data.optprods});
def( 'dtstock', 'idatable', {id:'shoprodata', elem:'stockmanage', paging:{pagesize:15}, tool:{cls:'tool', menu:[{id: 'prodadd', ico: {src: '{{ imgsurl }}/icos/add.png'}, label: {txt: '手工添加库存'}, fn:"amod({add:'stocks', title:'库存产品'});" }, { label: {txt: '-|-'} }, {id: 'prodedit', ico: {src: '{{ imgsurl }}/icos/page_edit.png'}, label: {txt: '调整'},fn:function(){var ofo=jsonForm(dtstock.form);if(hop(ofo,'guid')){amod({add:'stocks', title:'库存产品', mod:data.stocks[isArray(ofo.guid)?ofo.guid[0]:ofo.guid]});}}}, { label: {txt: '-|-'} }, {id: 'proddel', ico: {src: '{{ imgsurl }}/icos/delete.png'}, label: {txt: '删除'},fn:function(){ deldtdata(dtstock); } } ]},
    filter:{action:'/tiens/stock', col:{'pcode':'',pvtypename:{type:'select', value:'all', text:'所有PVBV类型', opts:function(){return getopts(data.pvtype,'guid','ptname');}}}},
    title:[{cls:'px80',text:'编码',col:'pcode'},{cls:'px220',text:'名称',col:'pname'},{cls:'px120',text:'规格',col:'spec'}, {cls:'px160',text:'PVBV类型',col:'pvtypename'}, {cls:'px30 t-c',text:'单位',col:'unit'}, {cls:'px50 t-r',text:'单价',col:'price'}, {cls:'px40 t-c',text:'图样',col:'ppic'}, {cls:'px50 t-r',text:'数量',col:'qty'}], data:data.stocks});
def( 'dtpo', 'idatable', {id:'podata', elem:'pomanage', paging:{pagesize:15}, tool:{cls:'tool', menu:[{id: 'podataadd', ico: {src: '{{ imgsurl }}/icos/add.png'}, label: {txt: '新增'}, fn:function(){oapop.show({data:$('poedit'), ico:'{{ imgsurl }}/icos/page_edit.png', title:'进货单明细'});} }, { label: {txt: '-|-'} }, {id: 'podataedit', ico: {src: '{{ imgsurl }}/icos/page_edit.png'}, label: {txt: '修改'},fn:function(){var ofo=jsonForm(dtpo.form);if(hop(ofo,'guid')){amod({add:'po',title:'销售项', mod:data.po[isArray(ofo.guid)?ofo.guid[0]:ofo.guid]});}}}, { label: {txt: '-|-'} }, {id: 'podatadel', ico: {src: '{{ imgsurl }}/icos/delete.png'}, label: {txt: '删除'},fn:function(){ deldtdata(dtpo); }} ]},
    filter:{action:'/tiens/po'},
    title:[{cls:'px140',text:'订单号',col:'orderno'}, {cls:'px60',text:'订单状态',col:'status'}, {cls:'px70',text:'日期',col:'date'}, {cls:'px60 t-r',text:'订货数量',col:'qty'}, {cls:'px70 t-r',text:'订单金额',col:'amount'}, {cls:'px80 t-r',text:'订单净额PV',col:'popv'}, {cls:'px80 t-r',text:'订单净额BV',col:'pobv'}], data:data.pos});

function getabdata(skey, odt, elmid){
    if(!data[skey]){
        data[skey]={};
        odt.data=data[skey];
    }
    try{odt.submit();}catch(e){}
return $(elmid);
}

def( 'sysplit', 'isplit', { id: 'sp2sys', elem:'sysmanage', content:$('syscont'), data:$('admindata') } );
def( 'prodsplit', 'isplit', { id: 'sp2prod', elem:'prodmanage', content:$('prodcont'), data:$('prodclsdata') } );

def( 'islsys', 'islist', { id:'syscontlist', elem:'syscont', list:[{label:'模块/功能',elem:'',target:''},{label:'基础表单',elem:'',target:''},{label:'表单项目',elem:'',target:''},{label:'帐号角色',elem:'roledata',target:'sp2sys_data'},{label:'管理员/用户',elem:'admindata',target:'sp2sys_data',cls:'act'}]} );
def( 'islprod', 'islist', { id:'prodcontlist', elem:'prodcont', list:[{label:'产品基本分类',elem:'prodclsdata',target:'sp2prod_data'},{label:'产品PVBV类型',elem:'prodpvtype',target:'sp2prod_data'},{label:'产品',elem:'prodata',target:'sp2prod_data',cls:'act'}]} );

def('oaitab', 'itab', {id: 'oatab', elem: 'navi', target:'cont', ttl:900, tabs: {
    syset: { id: 'oasys', tab: { label:'系统设置' }, locked:1, ico: {src: '{{ imgsurl }}/icos/wrench.png'}, data: function(){
        return getabdata('admins',dtadmin,'sysmanage');
        } },
    shop: { id: 'oastore', tab: { label:'公司/专卖店' }, locked:1, preload:1, ico: {src: '{{ imgsurl }}/icos/house.png'}, data: function(){
        return getabdata('cstore',dtcs,'cstoremanage');
        } },
    report: { id: 'oareport', tab: { label:'业绩' }, locked:1, ico: {src: '{{ imgsurl }}/icos/report.png'}, data: function(){ return getabdata('report',dtrpt,'rptmanage');return  } },
    stock: { id: 'oastock', tab: { label:'产品存货' }, locked:1, ico: {src: '{{ imgsurl }}/icos/bricks.png'}, data: function(){ return getabdata('stocks',dtstock,'stockmanage'); } },
    po: { id: 'oapo', tab: { label:'进货单' }, locked:1, ico: {src: '{{ imgsurl }}/icos/document-block.png'}, data: function(){ return getabdata('pos',dtpo,'pomanage'); } },
    user: { id: 'oavip', tab: { label:'顾客/业务员' }, locked:1, ico: {src: '{{ imgsurl }}/icos/vcard.png'}, data: function(){
        return getabdata('vips',dtvip,'vipmanage');
        } },
    sales: { id: 'oasale', tab: { label:'销售记录' }, locked:1, ico: {src: '{{ imgsurl }}/icos/money.png'}, data: function(){ return getabdata('sales',dtsale,'salemanage'); } },
    prod: { id: 'oaprod', tab: { label:'产品管理' }, locked:1, ico: {src: '{{ imgsurl }}/icos/bricks.png'}, data: function(){
        return getabdata('prods',dtprod,'prodmanage');
        } },
    info: { id: 'oainfo', rtl:1, notab:1, data:'{{ userinfo|safe }}' }
    } });

{% endblock %}
